<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: JobBoss::Boss</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/job_boss/boss_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/job_boss/boss.rb">lib/job_boss/boss.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">Object</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-config">::config</a></li>
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-c-queue">::queue</a></li>
					
					<li><a href="#method-c-queue_path">::queue_path</a></li>
					
					<li><a href="#method-c-resolve_path">::resolve_path</a></li>
					
					<li><a href="#method-i-available_employees">#available_employees</a></li>
					
					<li><a href="#method-i-cleanup_running_jobs">#cleanup_running_jobs</a></li>
					
					<li><a href="#method-i-config">#config</a></li>
					
					<li><a href="#method-i-establish_active_record_connection">#establish_active_record_connection</a></li>
					
					<li><a href="#method-i-kill_job">#kill_job</a></li>
					
					<li><a href="#method-i-logger">#logger</a></li>
					
					<li><a href="#method-i-require_job_classes">#require_job_classes</a></li>
					
					<li><a href="#method-i-shutdown_running_jobs">#shutdown_running_jobs</a></li>
					
					<li><a href="#method-i-start">#start</a></li>
					
					<li><a href="#method-i-stop">#stop</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="../Gemfile.html">Gemfile</a></li>
				
					<li class="file"><a href="../MIT-LICENSE.html">MIT-LICENSE</a></li>
				
					<li class="file"><a href="../Rakefile.html">Rakefile</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../JobBoss.html">JobBoss</a></li>
				
					<li><a href="../JobBoss/Boss.html">JobBoss::Boss</a></li>
				
					<li><a href="../JobBoss/Config.html">JobBoss::Config</a></li>
				
					<li><a href="../JobBoss/Job.html">JobBoss::Job</a></li>
				
					<li><a href="../JobBoss/Queuer.html">JobBoss::Queuer</a></li>
				
					<li><a href="../ActiveSupport.html">ActiveSupport</a></li>
				
					<li><a href="../ActiveSupport/TestCase.html">ActiveSupport::TestCase</a></li>
				
					<li><a href="../CreateJobs.html">CreateJobs</a></li>
				
					<li><a href="../DaemonTest.html">DaemonTest</a></li>
				
					<li><a href="../MathJobs.html">MathJobs</a></li>
				
					<li><a href="../Penguin.html">Penguin</a></li>
				
					<li><a href="../SleepJobs.html">SleepJobs</a></li>
				
					<li><a href="../StringJobs.html">StringJobs</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">JobBoss::Boss</h1>

		<div id="description">
			
		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="config-method" class="method-detail ">
				<a name="method-c-config"></a>

				<div class="method-heading">
				
					<span class="method-name">config</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Used to set <a href="Boss.html">Boss</a> configuration Usage:
</p>
<pre>
  Boss.config.sleep_interval = 2</pre>
					

					
					<div class="method-source-code"
						id="config-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 12</span>
12:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
13:         <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/config'</span>
14:         <span class="ruby-constant">Config</span>.<span class="ruby-identifier">new</span>
15:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-name">new</span><span
						class="method-args">(options = {})</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 58</span>
58:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span> = {})
59:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">application_root</span>     <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:working_dir</span>]
60:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">sleep_interval</span>       <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:sleep_interval</span>]
61:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">employee_limit</span>       <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:employee_limit</span>]
62:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>   <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:database_yaml_path</span>]
63:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>            <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:jobs_path</span>]
64: 
65:       <span class="ruby-ivar">@running_jobs</span> = []
66:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="queue-method" class="method-detail ">
				<a name="method-c-queue"></a>

				<div class="method-heading">
				
					<span class="method-name">queue</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Used to queue jobs Usage:
</p>
<pre>
  Boss.queue.math.is_prime?(42)</pre>
					

					
					<div class="method-source-code"
						id="queue-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 21</span>
21:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">queue</span>
22:         <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/queuer'</span>
23:         <span class="ruby-constant">Queuer</span>.<span class="ruby-identifier">new</span>
24:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="queue-path-method" class="method-detail ">
				<a name="method-c-queue_path"></a>

				<div class="method-heading">
				
					<span class="method-name">queue_path</span><span
						class="method-args">(path, *args)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Used to queue jobs Usage:
</p>
<pre>
  Boss.queue_path('math#in_prime?', 42)</pre>
					

					
					<div class="method-source-code"
						id="queue-path-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 30</span>
30:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">queue_path</span>(<span class="ruby-identifier">path</span>, *<span class="ruby-identifier">args</span>)
31:         <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">path</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'#'</span>)
32: 
33:         <span class="ruby-identifier">queue</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">controller</span>).<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action</span>, *<span class="ruby-identifier">args</span>)
34:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="resolve-path-method" class="method-detail ">
				<a name="method-c-resolve_path"></a>

				<div class="method-heading">
				
					<span class="method-name">resolve_path</span><span
						class="method-args">(path)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
If path starts with &#8217;/&#8217;, leave alone.  Otherwise, prepend
application_root
</p>
					

					
					<div class="method-source-code"
						id="resolve-path-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 37</span>
37:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">path</span>)
38:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span> <span class="ruby-operator">==</span> <span class="ruby-value">//</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/^#{config.application_root}/</span>)
39:           <span class="ruby-identifier">path</span>
40:         <span class="ruby-keyword kw">else</span>
41:           <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">application_root</span>, <span class="ruby-identifier">path</span>)
42:         <span class="ruby-keyword kw">end</span>
43:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="config-method" class="method-detail ">
				<a name="method-i-config"></a>

				<div class="method-heading">
				
					<span class="method-name">config</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="config-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 46</span>
46:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
47:       <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">config</span>
48:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="logger-method" class="method-detail ">
				<a name="method-i-logger"></a>

				<div class="method-heading">
				
					<span class="method-name">logger</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="logger-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 50</span>
50:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">logger</span>
51:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_path</span> = <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_path</span>)
52: 
53:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'logger'</span>
54:       <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">log_path</span>)
55:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="start-method" class="method-detail ">
				<a name="method-i-start"></a>

				<div class="method-heading">
				
					<span class="method-name">start</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Start the boss
</p>
					

					
					<div class="method-source-code"
						id="start-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 69</span>
 69:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
 70:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_record'</span>
 71:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'yaml'</span>
 72: 
 73:       <span class="ruby-identifier">establish_active_record_connection</span>
 74:       <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Started ActiveRecord connection in '#{config.environment}' environment from database YAML: #{config.database_yaml_path}&quot;</span>
 75: 
 76:       <span class="ruby-identifier">require_job_classes</span>
 77: 
 78:       <span class="ruby-constant">Signal</span>.<span class="ruby-identifier">trap</span>(<span class="ruby-value str">&quot;HUP&quot;</span>) <span class="ruby-keyword kw">do</span>
 79:         <span class="ruby-identifier">stop</span>
 80:       <span class="ruby-keyword kw">end</span>
 81: 
 82:       <span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
 83:         <span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span> <span class="ruby-operator">==</span> <span class="ruby-constant">BOSS_PID</span>
 84:       <span class="ruby-keyword kw">end</span>
 85: 
 86:       <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;Job Boss started&quot;</span>
 87:       <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Employee limit: #{Boss.config.employee_limit}&quot;</span>
 88: 
 89:       <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
 90:         <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">children_count</span> = <span class="ruby-identifier">available_employees</span>) <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
 91:           <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">sleep_interval</span>)
 92:           <span class="ruby-keyword kw">next</span>
 93:         <span class="ruby-keyword kw">end</span>
 94: 
 95:         <span class="ruby-comment cmt"># Go through each pending path so that we don't get stuck just processing</span>
 96:         <span class="ruby-comment cmt"># long running jobs which would leave quicker jobs to suffocate</span>
 97:         <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending_paths</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
 98:           <span class="ruby-identifier">job</span> = <span class="ruby-constant">Job</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">find_by_path</span>(<span class="ruby-identifier">path</span>)
 99:           <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">nil?</span>
100: 
101:           <span class="ruby-identifier">job</span>.<span class="ruby-identifier">dispatch</span>(<span class="ruby-keyword kw">self</span>)
102:           <span class="ruby-ivar">@running_jobs</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">job</span>
103: 
104:           <span class="ruby-identifier">children_count</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
105:           <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">children_count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
106:         <span class="ruby-keyword kw">end</span>
107: 
108:       <span class="ruby-keyword kw">end</span>
109:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="stop-method" class="method-detail ">
				<a name="method-i-stop"></a>

				<div class="method-heading">
				
					<span class="method-name">stop</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="stop-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 111</span>
111:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
112:       <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Stopping #{@running_jobs.size} running employees...&quot;</span>
113: 
114:       <span class="ruby-identifier">shutdown_running_jobs</span>
115: 
116:       <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;Job Boss stopped&quot;</span>
117:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="private-instance-method-details" class="method-section section">
			<h3 class="section-header">Private Instance Methods</h3>

		
			<div id="available-employees-method" class="method-detail ">
				<a name="method-i-available_employees"></a>

				<div class="method-heading">
				
					<span class="method-name">available_employees</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Total number of employees which can be run
</p>
					

					
					<div class="method-source-code"
						id="available-employees-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 142</span>
142:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">available_employees</span>
143:       <span class="ruby-identifier">cleanup_running_jobs</span>
144: 
145:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">employee_limit</span> <span class="ruby-operator">-</span> <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">size</span>
146:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="cleanup-running-jobs-method" class="method-detail ">
				<a name="method-i-cleanup_running_jobs"></a>

				<div class="method-heading">
				
					<span class="method-name">cleanup_running_jobs</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Cleans up @running_jobs variable, getting rid of jobs which have completed,
which have been cancelled, or which went MIA
</p>
					

					
					<div class="method-source-code"
						id="cleanup-running-jobs-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 122</span>
122:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cleanup_running_jobs</span>
123:       <span class="ruby-constant">Job</span>.<span class="ruby-identifier">uncached</span> <span class="ruby-keyword kw">do</span>
124:         <span class="ruby-ivar">@running_jobs</span> = <span class="ruby-constant">Job</span>.<span class="ruby-identifier">running</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value str">'id in (?)'</span>, <span class="ruby-ivar">@running_jobs</span>)
125: 
126:         <span class="ruby-identifier">cancelled_jobs</span> = <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">select</span>(&amp;<span class="ruby-value">:cancelled?</span>)
127:         <span class="ruby-identifier">cancelled_jobs</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">job</span><span class="ruby-operator">|</span> <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>) }
128:         <span class="ruby-ivar">@running_jobs</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">cancelled_jobs</span>
129: 
130:         <span class="ruby-comment cmt"># Clean out any jobs whos processes have stopped running for some reason</span>
131:         <span class="ruby-ivar">@running_jobs</span> = <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">select</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
132:           <span class="ruby-keyword kw">begin</span>
133:             <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">job</span>.<span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">to_i</span>)
134:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
135:             <span class="ruby-keyword kw">nil</span>
136:           <span class="ruby-keyword kw">end</span>
137:         <span class="ruby-keyword kw">end</span>
138:       <span class="ruby-keyword kw">end</span>
139:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="establish-active-record-connection-method" class="method-detail ">
				<a name="method-i-establish_active_record_connection"></a>

				<div class="method-heading">
				
					<span class="method-name">establish_active_record_connection</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="establish-active-record-connection-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 148</span>
148:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">establish_active_record_connection</span>
149:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span> = <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>)
150: 
151:       <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Database YAML file missing (#{config.database_yaml_path})&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>)
152: 
153:       <span class="ruby-identifier">config_data</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">database_yaml_path</span>))
154: 
155:       <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">remove_connection</span>
156:       <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">config_data</span>[<span class="ruby-identifier">config</span>.<span class="ruby-identifier">environment</span>])
157: 
158:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'job_boss/job'</span>
159:       <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">table_exists?</span>
160:         <span class="ruby-identifier">require</span> <span class="ruby-value str">'migrate'</span>
161:         <span class="ruby-constant">CreateJobs</span>.<span class="ruby-identifier">up</span>
162:       <span class="ruby-keyword kw">end</span>
163:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="kill-job-method" class="method-detail ">
				<a name="method-i-kill_job"></a>

				<div class="method-heading">
				
					<span class="method-name">kill_job</span><span
						class="method-args">(job)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="kill-job-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 173</span>
173:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>)
174:       <span class="ruby-keyword kw">begin</span>
175:         <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value str">&quot;TERM&quot;</span>, <span class="ruby-identifier">job</span>.<span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">to_i</span>)
176:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
177:         <span class="ruby-keyword kw">nil</span>
178:       <span class="ruby-keyword kw">end</span>
179:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="require-job-classes-method" class="method-detail ">
				<a name="method-i-require_job_classes"></a>

				<div class="method-heading">
				
					<span class="method-name">require_job_classes</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="require-job-classes-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 165</span>
165:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">require_job_classes</span>
166:       <span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span> = <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">resolve_path</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>)
167: 
168:       <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Jobs path missing (#{config.jobs_path})&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>)
169: 
170:       <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">config</span>.<span class="ruby-identifier">jobs_path</span>, <span class="ruby-value str">'*.rb'</span>)).<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">job_class</span><span class="ruby-operator">|</span> <span class="ruby-identifier">require</span> <span class="ruby-identifier">job_class</span> }
171:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="shutdown-running-jobs-method" class="method-detail ">
				<a name="method-i-shutdown_running_jobs"></a>

				<div class="method-heading">
				
					<span class="method-name">shutdown_running_jobs</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="shutdown-running-jobs-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/boss.rb, line 181</span>
181:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown_running_jobs</span>
182:       <span class="ruby-identifier">cleanup_running_jobs</span>
183: 
184:       <span class="ruby-ivar">@running_jobs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
185:         <span class="ruby-identifier">kill_job</span>(<span class="ruby-identifier">job</span>)
186:         <span class="ruby-identifier">job</span>.<span class="ruby-identifier">mark_for_redo</span>
187:       <span class="ruby-keyword kw">end</span>
188:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

